package com.lanling.eduservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lanling.eduservice.entity.EduComment;
import com.lanling.eduservice.mapper.EduCommentMapper;
import com.lanling.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author 胡振华
 * @since 2021-03-04
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public Map<String, Object> getCoursePageList(Page<EduComment> eduCommentPage,String courseid) {
        QueryWrapper<EduComment> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id",courseid);
        queryWrapper.orderByDesc("gmt_create");
        IPage<EduComment> eduCommentIPage = baseMapper.selectPage(eduCommentPage, queryWrapper);
        List<EduComment> records = eduCommentIPage.getRecords();
        long current = eduCommentIPage.getCurrent();
        long pages = eduCommentIPage.getPages();
        long size = eduCommentIPage.getSize();
        long total = eduCommentIPage.getTotal();
        Map<String,Object> map = new HashMap<>();
        map.put("current",current);
        map.put("pages",pages);
        map.put("size",size);
        map.put("total",total);
        map.put("records",records);
        return map;
    }

    //添加课程评论
    @Override
    public boolean addComment(EduComment eduComment) {
        int insert = baseMapper.insert(eduComment);
        return insert==0?false:true;
    }
}
